package com.zy.dao.impl;

import com.zy.dao.AddOrderDao;
import com.zy.utils.JdbcUtil;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class AddOrderDaoImpl implements AddOrderDao {

    @Override
    public void insertOrder(BigDecimal paymentAmount, Date paymentTime, int userId) {
        String sql = "INSERT INTO tb_order (payment_amount, payment_time, user_id) VALUES (?, ?, ?)";
        try (Connection connection = JdbcUtil.getConnection();
             PreparedStatement stmt = connection.prepareStatement(sql)) {
            stmt.setBigDecimal(1, paymentAmount);
            stmt.setTimestamp(2, new java.sql.Timestamp(paymentTime.getTime()));
            stmt.setInt(3, userId);
            stmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
